<!--
 * @Author: xjt
 * @Date: 2021-06-24 23:10:47
 * @LastEditTime: 2021-06-30 20:30:53
 * @Description: 人员接收跟踪
 * @LastEditors: cqg
-->
<template>
  <basic-container v-loading="loading" element-loading-text="数据加载中...">
    <dataList
      :pageInfo="pager"
      :listData="tableData"
      :menuList="[]"
      :listLayout="[]"
      searchName="hotelName"
      @menu-click="handleMenuClick"
      :filterList="filterList"
      :dataInfo="dataInfo"
      :operaInfo="operaInfo"
      :openIndex="true"
      operaColumnWidth="120"
      @btn-click="handleBtnClick"
      placeholder="请输入隔离点名称"
      :hideFilterBtn="true"
      style="margin-top:-30px"
    ></dataList>

    <hotelDialog width="80%" :popUpdata="popUpdata" ref="hotelDialog"></hotelDialog>
  </basic-container>
</template>
<script>
import { gettrashpage, restroePerson } from '@/views/yq-personnel/api/check.js';
import { mapGetters } from 'vuex';
import { tableOption } from './const';
import hotelDialog from './dialog';
import { extractName } from '@/utils/extract';

export default {
  components: {
    hotelDialog,
  },
  provide () {
    return {
      //初始化数据
      initList: this.queryData,
    };
  },
  beforeMount () {
    this.queryData();
  },
  data () {
    return {
      // 表格列表数据
      tableData: [],
      // 请求参数
      params: {
        current: 1,
        size: 20,
        keyword: '',
      },
      // 选中的数据
      selectDataArr: [],
      // 分页
      pager: {
        total: 0, // 总页数
        current: 1, // 当前页数
        size: 20, // 每页显示多少条
      },
      // 页面loading
      loading: false,
      filterList: tableOption.filterList,
      popUpdata: [
        { label: '消杀时间', value: '', key: 'h', type: 'input' },
        { label: '消杀人', value: '', key: 'i', type: 'input' },
        { label: '登记人', value: '', key: 'k', type: 'input' },
        { label: '备注', value: '', key: 't', type: 'textarea', class: 'full' },
      ],
      healthData: [
        { label: '姓名', value: '', key: 'a1', type: 'input' },
        { label: '身份证号/其他证件', value: '', key: 'a2', type: 'input' },
        {
          label: '性别',
          value: '',
          key: 'a3',
          type: 'dict',
          dictName: 'gender',
        },
        { label: '国籍', value: '', key: 'a4', type: 'input' },
        { label: '民族', value: '', key: 'a5', type: 'input' },
        { label: '年龄', value: '', key: 'a6', type: 'input' },
        { label: '手机号码', value: '', key: 'a7', type: 'input' },
        { label: '居住地址', value: '', key: 'a8', type: 'input' },
        { label: '入住驿站', value: '', key: 'a9', type: 'input' },
        { label: '入住房号', value: '', key: 'a10', type: 'input' },
        {
          label: '入住日期',
          value: '',
          key: 'a11',
          type: 'time',
          genre: 'datetime',
        },
        {
          label: '高血压',
          value: '',
          key: 'a12',
          type: 'dict',
          dictName: 'is_valid',
        },
        {
          label: '高血糖',
          value: '',
          key: 'a13',
          type: 'dict',
          dictName: 'is_valid',
        },
        {
          label: '高血脂',
          value: '',
          key: 'a14',
          type: 'dict',
          dictName: 'is_valid',
        },
        {
          label: '心脏病',
          value: '',
          key: 'a15',
          type: 'dict',
          dictName: 'is_valid',
        },
        {
          label: '癫痫病',
          value: '',
          key: 'a16',
          type: 'dict',
          dictName: 'is_valid',
        },
        {
          label: '精神类疾病',
          value: '',
          key: 'a17',
          type: 'dict',
          dictName: 'is_valid',
        },
        {
          label: '是否安装支架',
          value: '',
          key: 'a18',
          type: 'dict',
          dictName: 'is_valid',
        },
        {
          label: '是否有搭桥',
          value: '',
          key: 'a19',
          type: 'dict',
          dictName: 'is_valid',
        },
        {
          label: '是否有脑梗病史',
          value: '',
          key: 'a20',
          type: 'dict',
          dictName: 'is_valid',
        },
        {
          label: '慢性呼吸系统疾病',
          value: [],
          key: 'a21',
          type: 'select',
          multiple: true,
          options: [
            { label: '肺结核', value: 0 },
            { label: '慢阻肺', value: 1 },
            { label: '肺气肿', value: 2 },
            { label: '哮喘', value: 3 },
          ],
        },
        {
          label: '疟疾等重点传染疾病同史',
          value: '',
          key: 'a22',
          type: 'input',
        },
        { label: '隔离点负责人', value: '', key: 'a23', type: 'input' },
        {
          label: '其它需重点关注疾病或情况',
          value: '',
          key: 'a24',
          type: 'input',
        },
        { label: '有无既往手术史', value: '', key: 'a25', type: 'input' },
        { label: '有无食物或药物过敏', value: '', key: 'a26', type: 'input' },
        { label: '有无怀孕', value: '', key: 'a27', type: 'input' },
        { label: '携带何种药物', value: '', key: 'a28', type: 'input' },
        { label: '抽烟及数量（包/天）', value: '', key: 'a29', type: 'input' },
        { label: '饮酒及数量（两/天）', value: '', key: 'a30', type: 'input' },
        {
          label: '入住隔离点/驿站是否感到紧张',
          value: '',
          key: 'a31',
          type: 'input',
        },
        { label: '紧急联系人姓名', value: '', key: 'a32', type: 'input' },
        { label: '紧急联系人关系', value: '', key: 'a33', type: 'input' },
        { label: '紧急联系人电话', value: '', key: 'a34', type: 'input' },
        { label: '紧急联系人住址', value: '', key: 'a35', type: 'input' },
      ],
    };
  },
  computed: {
    ...mapGetters(['permissions']),
    // 表格展示数据
    dataInfo () {
      return [
        { label: '隔离点名称', prop: 'hotelName' },
        { label: '所属街道', prop: 'hotelStreet' },
        { label: '房号', prop: 'roomNum' },
        { label: '姓名', prop: 'name' },
        { label: '证件号码', prop: 'cardId' },
        { label: '联系方式', prop: 'telPhone' },
        { label: '国籍地区', prop: 'moveNum' },
        { label: '来源', prop: 'dataSource', formatter: this.dataFormatter },
        { label: '风险等级', prop: 'riskLevel', formatter: this.dataFormatter },
        { label: '剩余天数', prop: 'surplusDays' },
        { label: '入住时间', prop: 'moveStartTime' },
        { label: '解除隔离时间', prop: 'releaseIsolationDate' },
        { label: '离点时间', prop: 'leaveHotelDate' },
        { label: '人员状态', prop: 'personState' },
      ];
    },
    // 操作按钮
    operaInfo () {
      return ['preview', { label: '还原', name: 'restore' }];
    },
  },
  methods: {
    // 数据请求
    queryData (params = {}) {
      this.loading = true;
      let requestData = { ...this.params, ...params };
      console.log(requestData);
      gettrashpage(requestData)
        .then((res) => {
          const { current, size, total, records } = res.data.data;
          this.tableData = records;
          this.params = requestData;
          this.pager = { total, current, size };
        })
        .finally(() => {
          this.loading = false;
        });
    },
    //表格按钮点击事件监听
    handleBtnClick (row = {}) {
      console.log(row);
      if (row.type === 'restore') {
        this.$confirm(`是否确认恢复 "${row.row.name}" 这条数据?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(async () => {
            const data = await restroePerson({ personId: row.row.personId });
            this.$message({
              type: 'success',
              message: '还原成功!',
            });
            this.queryData();
          })
          .catch(() => { });
      } else if (row.type === 'preview') {
      }
    },

    // 菜单点击监听
    handleMenuClick (type) {
      switch (type) {
        case 'export':
          // 导出
          /*   this.publicExport(
            row.fileName,
            `/admin/sys-file/download/${row.bucketName}/${row.id}`
          ); */
          break;
        default:
          this.$message(type);
          break;
      }
    },

    //格式化表格字典值
    dataFormatter (row, column, cellValue) {
      switch (column.property) {
        case 'dataSource':
          return extractName('data_source', row.dataSource);
        case 'riskLevel':
          return extractName('risk_level', row.riskLevel);
        default:
          break;
      }
    },
    // 获取索引值
    getIndex (index) {
      const { current = 0, size = 0 } = this.pager;
      return (current - 1) * size + (index + 1);
    },
    // 删除数据
    async deleteData (data) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          try {
            await deleteQuestion(data);
            this.$message.success('删除成功!');
            this.queryData({ current: 1 });
          } catch (error) {
            this.$message.fail('删除失败!');
          }
        })
        .catch(() => {
          this.$message.info('已取消删除');
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.operateMain {
  /deep/ .top-buttons {
    float: right;
    width: 50%;
  }
  /deep/ .v-search {
    width: 50%;
    justify-content: flex-start;
  }
  /deep/ .operaColumn .el-button {
    color: var(--color);
  }
}
</style>
